/**
 * 时间  ：2015-08-05
 * 功能  ：用于用户注册表单验证
 */
var registerValidator = function() {  

    var handleSubmit = function() {  

        $('#form').validate({

            errorElement : 'span',  

            errorClass : 'help-block',  
            
            onfocusout: function(element) { $(element).valid(); } ,

            rules : {  
            	userName : {  
                    required : true ,
                    remote:{                                          //验证用户名是否存在
                        type:"POST",
                        url:"/application/reg/userName",
                        data:{
                        	userName:function(){return $("#userName").val();}
                        } 
                       } 
                },  

                password : {  
                    required : true,
                    //passwords:true
                }, 
                
                repassword : {  
                    required : true,
                    equalTo:"#password"
                },
                email : {  
                    required : true , 
                    email:true ,
                    remote:{                                          //验证邮箱是否存在
                        type:"POST",
                        url:"/application/reg/email",
                        async:false,//servlet
                        data:{
                            email:function(){return $("#email").val();}
                        } 
                      } 
                },
                identifycode: {
                	required:true,
                	 remote:{                                          //验证验证码
                         type:"POST",
                         async:false,async:false,
                         url:"",
                         data:{
                         	code:function(){return $("#identifycode").val();},
                         	mobile:function(){return $("#verifytel").val();}
                         } 
                       } 
                },
                checkraw:{
                	required:true
                }
            },  

            messages : {  

            	userName : { 
                    required : "请输入您的用户名",
                    remote:"此账号已注册，请重新输入"
                },  

                password : {
                    required : "请输入您的密码"
                },
                repassword : {
                    required : "请输入您的密码", 
                    equalTo:"两次输入不一致，请重新输入"
                },
                email :  {  
                    required : "请输入绑定邮箱",
                    email:"请输入正确的邮箱地址",
                    remote:"该邮箱已绑定，请更换新的邮箱"
                },
                identifycode :  {  
                	required:"请输入验证码",
                	remote:"请输入正确的验证码"
                },
                checkraw:{
                	required:""
                }

            },  

            highlight : function(element) {  
                $(element).closest('#reg').addClass('error');  
            },  
            success : function(label) {  
                label.closest('#reg').removeClass('error');  
                label.remove();  
            },  

            errorPlacement : function(error, element) {  
                element.parent('div').append(error);  
            }
             ,  

             submitHandler : function(form) {  
                 if (!$('#reg').validate().form()) { 
                      return false;  
                  }
          			return true;
            }

        });  

    }  

    return {  
        init : function() {  
            handleSubmit();  
        }  

    };  

}(); 